﻿using System;
using System.Net;
using System.Runtime.Serialization;
using Microsoft.Practices.Composite.Presentation.Commands;
using System.Xml.Serialization;

namespace BusinessObjects
{
#if Silverlight
    [Serializable]
#else
    [DataContract]
#endif
    [KnownType( typeof( Player ) )]
    [KnownType( typeof( Rubbish ) )]
    [KnownType( typeof( Herb ) )]
    public class GameObject : BaseBusinessObject
    {
        private double x;
        private double y;

        private double width;
        private double height;

        private string description;
        private int zIndex = 0;
        private double scale = 1;
        private ObjectsType type;
        private bool isEnabled = true;
        private string image;

        [DataMember]
        public double X
        {
            get
            {
                return this.x;
            }
            set
            {
                if ( this.x != value )
                {
                    this.x = value;
                    base.NotifyPropertyChanged( "X" );
                }
            }
        }

        [DataMember]
        public double Y
        {
            get
            {
                return this.y;
            }
            set
            {
                if ( this.y != value )
                {
                    this.y = value;
                    base.NotifyPropertyChanged( "Y" );
                }
            }
        }

        [DataMember]
        public int GridX
        {
            get;
            set;
        }

        [DataMember]
        public int GridY
        {
            get;
            set;
        }

        [DataMember]
        public double Width
        {
            get
            {
                return this.width;
            }
            set
            {
                if ( this.width != value )
                {
                    this.width = value;
                    base.NotifyPropertyChanged( "Width" );
                }
            }
        }

        [DataMember]
        public double Height
        {
            get
            {
                return this.height;
            }
            set
            {
                if ( this.height != value )
                {
                    this.height = value;
                    base.NotifyPropertyChanged( "Height" );
                }
            }
        }

        [DataMember]
        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                if ( this.description != value )
                {
                    this.description = value;
                    this.NotifyPropertyChanged( "Description" );
                }
            }
        }

        [DataMember]
        public double Scale
        {
            get
            {
                return this.scale;
            }
            set
            {
                if ( this.scale != value )
                {
                    this.scale = value;
                    base.NotifyPropertyChanged( "Scale" );
                }
            }
        }

        [DataMember]
        public int ZIndex
        {
            get { return this.zIndex; }
            set
            {
                if ( this.zIndex != value )
                {
                    this.zIndex = value;
                    base.NotifyPropertyChanged( "ZIndex" );
                }
            }
        }

        [DataMember]
        public string Image
        {
            get
            {
                return this.image;
            }
            set
            {
                if ( this.image == value )
                    return;

                this.image = value;
                this.NotifyPropertyChanged( "Image" );
            }
        }

        [DataMember]
        public ObjectsType Type
        {
            get
            {
                return this.type;
            }
            set
            {
                if ( this.type != value )
                {
                    this.type = value;
                    base.NotifyPropertyChanged( "Type" );
                }
            }
        }

        [DataMember]
        public bool IsEnabled
        {
            get
            {
                return this.isEnabled;
            }
            set
            {
                if ( this.isEnabled == value )
                    return;

                this.isEnabled = value;
                this.NotifyPropertyChanged( "IsEnabled" );
            }
        }

        public override bool Equals( object obj )
        {
            GameObject target = obj as GameObject;

            if ( target == null )
                return false;

            return target.Id == this.Id && target.GridX == this.GridX && target.GridY == this.GridY;
        }
    }
}
